// pages/convenient/convenient.js
var Bmob = require('../../utils/bmob.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    things_list: [],
    inputShowed: false,
    inputVal: "",
    height: 0
  },
  tapPhoneCallHandler: function (e) {

    app.tapPhoneCallHandler(e);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   console.log(options)
    var type=options.type;
    this.getheight();
    this.get_thingsList(type);
  },
  getheight: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {

        that.setData({
          height: res.windowHeight - 46
        })
      }
    })
  },
  showInput: function () {
    this.setData({
      inputShowed: true
    });

  },
  hideInput: function () {
    var that = this;
    this.setData({
      inputVal: "",
      inputShowed: false
    });
    that.get_thingsList();
  },
  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },
  inputTyping: function (e) {
    this.setData({
      inputVal: e.detail.value
    });
  },

  turnTothingsDetail: function (e) {
    console.log(e)
    var id = e.currentTarget.dataset.id;
    var thingstype = e.currentTarget.dataset.type;

    wx.navigateTo({
      url: "../../pages/things/things?detail=" + id + "&type=" + thingstype
    })
  },
  search: function (e) {
    var that = this;
    var search_str = that.data.inputVal;
    var Franchisee = Bmob.Object.extend("things");
    var franchisee = new Bmob.Query(Franchisee);
     franchisee.equalTo("things_title", search_str);
    franchisee.descending('createdAt');  //排序

    franchisee.find({
      success: function (res) {
        //var goods=res;

        that.setData({

          franchisee: res

        })

      },
      complete: function () {

      }
    });

  },
  get_thingsList: function (param) {
    var that = this;
    var things_type=param;
    var Things = Bmob.Object.extend("things");
    var things = new Bmob.Query(Things);
    things.equalTo("type", Number(things_type));
  
   things.descending('createdAt');  //排序

    things.find({
      success: function (res) {
        //var goods=res;

        that.setData({

          things_list: res

        })

      },
      complete: function () {

      }
    });


  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})